package com.shujia.Redis;

import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

public class RedisApi {
    Jedis jedis;
    @Before
    public void init(){
         jedis = new Jedis("master",6379);
    }
    @Test
    public  void Student() {
        FileReader fileReader;
        try {
            fileReader = new FileReader("data/students.txt");
            BufferedReader reader = new BufferedReader(fileReader);
            String l;
            while ((l = reader.readLine())!=null){
                String id = "Student:"+l.split(",")[0];
                String[] split = l.split(",");
                HashMap<String,String> HashMap = new HashMap<>();

                String name = split[1];
                String age = split[2];
                String gender = split[3];
                String clazz = split[4];

                HashMap.put("name",name);
                HashMap.put("age",age);
                HashMap.put("gender",gender);
                HashMap.put("clazz",clazz);

                jedis.hmset(id,HashMap);

            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

//        String k1 = jedis.get("k1");
//        System.out.println(k1);
//        jedis.set("k2", "shijian ");
//        String k2 = jedis.get("k2");
//        System.out.println(k2);

    }
}
